import { Vec3, Node, _decorator } from "cc";
const { ccclass, property } = _decorator;

export class Tools {

    /**
     * 判断两个物体是否再区间相交
     */
    public static isIntersect(_node0: Node, _node1: Node, _hor: number, _ver: number): boolean {

        let pos0: Vec3 = _node0.getWorldPosition();
        let pos1: Vec3 = _node1.getWorldPosition();

        if (Math.abs(pos0.x - pos1.x) < _hor && Math.abs(pos0.y - pos1.y) < _ver) {
            return true;
        }

        return false;
    }

    /**
    * 数字转时间格式
    * @param sec 
    * @returns 
    */
    static secondsFormat(sec, havehour: boolean) {
        let hour = Math.floor(sec / 3600);
        let minute = Math.floor((sec - hour * 3600) / 60);
        let second = sec - hour * 3600 - minute * 60;
        let hour1 = ''
        let minute1 = ''
        let second1 = ''
        if (hour < 10) {
            hour1 = "0" + hour;
        } else {
            hour1 = "" + hour;
        }
        if (minute < 10) {
            minute1 = "0" + minute;
        } else {
            minute1 = "" + minute;
        }
        if (second < 10) {
            second1 = "0" + second;
        } else {
            second1 = "" + second;
        }
        if (havehour) {
            return hour1 + "：" + minute1 + "：" + second1;
        } else {
            return minute1 + "：" + second1;
        }
    }

}


